/*
 * ImageLoader.java
 *
 * Copyright 2007, 2008 Tiberiumlabs
 *
 * This file is part of Tiberiumlabs Lailaps.
 *
 * Tiberiumlabs Lailaps is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * Tiberiumlabs Lailaps is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.tiberiumlabs.lailaps.resources;

import java.util.WeakHashMap;
import javax.swing.ImageIcon;

/**
 *
 * @author <a href="mailto:paranoid.tiberiumlabs@gmail.com">Paranoid</a>
 */
// TODO think about themes in future versions...
public class ImageLoader {

    // TODO check where ImageIcon is stored.
    //if it is read every time = no need in WeakHashMap
    private static WeakHashMap<String, ImageIcon> imageMap = new WeakHashMap<String, ImageIcon>();

    // <editor-fold defaultstate="collapsed" desc=" button icons ">

    private static final String BUTTON_OK = "images/button_ok.png";
    public static ImageIcon getButtonOkIcon() {
        ImageIcon icon = imageMap.get(BUTTON_OK);
        if (icon == null) {
            icon = new ImageIcon(ImageLoader.class.getResource(BUTTON_OK));
            imageMap.put(BUTTON_OK, icon);
        }
        return icon;
    }

    private static final String BUTTON_CANCEL = "images/button_cancel.png";
    public static ImageIcon getButtonCancelIcon() {
        ImageIcon icon = imageMap.get(BUTTON_CANCEL);
        if (icon == null) {
            icon = new ImageIcon(ImageLoader.class.getResource(BUTTON_CANCEL));
            imageMap.put(BUTTON_CANCEL, icon);
        }
        return icon;
    }

    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc=" toolbars ">

    private static final String SAVEAS_IMAGE = "images/toolbar/filesaveas.png";
    public static ImageIcon getSaveAsIcon() {
        ImageIcon icon = imageMap.get(SAVEAS_IMAGE);
        if (icon == null) {
            icon = new ImageIcon(ImageLoader.class.getResource(SAVEAS_IMAGE));
            imageMap.put(SAVEAS_IMAGE, icon);
        }
        return icon;
    }

    private static final String SAVE_IMAGE = "images/toolbar/save_all.png";
    public static ImageIcon getSaveIcon() {
        ImageIcon icon = imageMap.get(SAVE_IMAGE);
        if (icon == null) {
            icon = new ImageIcon(ImageLoader.class.getResource(SAVE_IMAGE));
            imageMap.put(SAVE_IMAGE, icon);
        }
        return icon;
    }

    private static final String CLEAR_IMAGE = "images/clear.png";
    public static ImageIcon getClearIcon() {
        ImageIcon icon = imageMap.get(CLEAR_IMAGE);
        if (icon == null) {
            icon = new ImageIcon(ImageLoader.class.getResource(CLEAR_IMAGE));
            imageMap.put(CLEAR_IMAGE, icon);
        }
        return icon;
    }

    private static final String REMOVE_IMAGE = "images/toolbar/remove.png";
    public static ImageIcon getRemoveIcon() {
        ImageIcon icon = imageMap.get(REMOVE_IMAGE);
        if (icon == null) {
            icon = new ImageIcon(ImageLoader.class.getResource(REMOVE_IMAGE));
            imageMap.put(REMOVE_IMAGE, icon);
        }
        return icon;
    }

    private static final String EDIT_IMAGE = "images/toolbar/edit.png";
    public static ImageIcon getEditIcon() {
        ImageIcon icon = imageMap.get(EDIT_IMAGE);
        if (icon == null) {
            icon = new ImageIcon(ImageLoader.class.getResource(EDIT_IMAGE));
            imageMap.put(EDIT_IMAGE, icon);
        }
        return icon;
    }

    private static final String OPEN_IMAGE_SMALL = "images/folder_small.png";
    public static ImageIcon getOpenImageSmall() {
        ImageIcon icon = imageMap.get(OPEN_IMAGE_SMALL);
        if (icon == null) {
            icon = new ImageIcon(ImageLoader.class.getResource(OPEN_IMAGE_SMALL));
            imageMap.put(OPEN_IMAGE_SMALL, icon);
        }
        return icon;
    }

    private static final String ADD_IMAGE = "images/toolbar/add.png";
    public static ImageIcon getAddImage() {
        ImageIcon icon = imageMap.get(ADD_IMAGE);
        if (icon == null) {
            icon = new ImageIcon(ImageLoader.class.getResource(ADD_IMAGE));
            imageMap.put(ADD_IMAGE, icon);
        }
        return icon;
    }

    private static final String SETTINGS_IMAGE = "images/toolbar/settings.png";
    public static ImageIcon getSettingsIcon() {
        ImageIcon icon = imageMap.get(SETTINGS_IMAGE);
        if (icon == null) {
            icon = new ImageIcon(ImageLoader.class.getResource(SETTINGS_IMAGE));
            imageMap.put(SETTINGS_IMAGE, icon);
        }
        return icon;
    }

    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc=" small menu icons ">

    private static final String MENU_EXIT_ICON = "images/menu/exit.png";
    public static ImageIcon getMenuExitIcon() {
        ImageIcon icon = imageMap.get(MENU_EXIT_ICON);
        if (icon == null) {
            icon = new ImageIcon(ImageLoader.class.getResource(MENU_EXIT_ICON));
            imageMap.put(MENU_EXIT_ICON, icon);
        }
        return icon;
    }

    private static final String MENU_SETTINGS_ICON = "images/menu/settings.png";
    public static ImageIcon getMenuSettings() {
        ImageIcon icon = imageMap.get(MENU_SETTINGS_ICON);
        if (icon == null) {
            icon = new ImageIcon(ImageLoader.class.getResource(MENU_SETTINGS_ICON));
            imageMap.put(MENU_SETTINGS_ICON, icon);
        }
        return icon;
    }
    
    private static final String MENU_ADD_ICON = "images/menu/add.png";
    public static ImageIcon getMenuAddIcon() {
        ImageIcon icon = imageMap.get(MENU_ADD_ICON);
        if (icon == null) {
            icon = new ImageIcon(ImageLoader.class.getResource(MENU_ADD_ICON));
            imageMap.put(MENU_ADD_ICON, icon);
        }
        return icon;
    }
    
    private static final String MENU_SAVE_ICON = "images/menu/save_all.png";
    public static ImageIcon getMenuSaveIcon() {
        ImageIcon icon = imageMap.get(MENU_SAVE_ICON);
        if (icon == null) {
            icon = new ImageIcon(ImageLoader.class.getResource(MENU_SAVE_ICON));
            imageMap.put(MENU_SAVE_ICON, icon);
        }
        return icon;
    }
    
    private static final String MENU_SAVE_AS_ICON = "images/menu/filesaveas.png";
    public static ImageIcon getMenuSaveAsIcon() {
        ImageIcon icon = imageMap.get(MENU_SAVE_AS_ICON);
        if (icon == null) {
            icon = new ImageIcon(ImageLoader.class.getResource(MENU_SAVE_AS_ICON));
            imageMap.put(MENU_SAVE_AS_ICON, icon);
        }
        return icon;
    }
    
    private static final String MENU_START_ICON = "images/menu/start.png";
    public static ImageIcon getMenuStartIcon() {
        ImageIcon icon = imageMap.get(MENU_START_ICON);
        if (icon == null) {
            icon = new ImageIcon(ImageLoader.class.getResource(MENU_START_ICON));
            imageMap.put(MENU_START_ICON, icon);
        }
        return icon;
    }
    
    private static final String MENU_PAUSE_ICON = "images/menu/pause.png";
    public static ImageIcon getMenuPauseIcon() {
        ImageIcon icon = imageMap.get(MENU_PAUSE_ICON);
        if (icon == null) {
            icon = new ImageIcon(ImageLoader.class.getResource(MENU_PAUSE_ICON));
            imageMap.put(MENU_PAUSE_ICON, icon);
        }
        return icon;
    }
    
    private static final String MENU_STOP_ICON = "images/menu/stop.png";
    public static ImageIcon getMenuStopIcon() {
        ImageIcon icon = imageMap.get(MENU_STOP_ICON);
        if (icon == null) {
            icon = new ImageIcon(ImageLoader.class.getResource(MENU_STOP_ICON));
            imageMap.put(MENU_STOP_ICON, icon);
        }
        return icon;
    }

    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc=" download actions ">

    private static final String START_IMAGE = "images/toolbar/start.png";
    public static ImageIcon getStartImage() {
        ImageIcon icon = imageMap.get(START_IMAGE);
        if (icon == null) {
            icon = new ImageIcon(ImageLoader.class.getResource(START_IMAGE));
            imageMap.put(START_IMAGE, icon);
        }
        return icon;
    }

    private static final String STOP_IMAGE = "images/toolbar/stop.png";
    public static ImageIcon getStopImage() {
        ImageIcon icon = imageMap.get(STOP_IMAGE);
        if (icon == null) {
            icon = new ImageIcon(ImageLoader.class.getResource(STOP_IMAGE));
            imageMap.put(STOP_IMAGE, icon);
        }
        return icon;
    }

    private static final String PAUSE_IMAGE = "images/toolbar/pause.png";
    public static ImageIcon getPuseImage() {
        ImageIcon icon = imageMap.get(PAUSE_IMAGE);
        if (icon == null) {
            icon = new ImageIcon(ImageLoader.class.getResource(PAUSE_IMAGE));
            imageMap.put(PAUSE_IMAGE, icon);
        }
        return icon;
    }

    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc=" status icons in 16x16 size ">

    private static final String STATUS_STOPPED = "images/status/stopped.png";
    private static final String STATUS_PREPARING = "images/status/preparing.png";
    private static final String STATUS_WORKING = "images/status/working.png";
    private static final String STATUS_WAITING = "images/status/waiting.png";
    private static final String STATUS_PAUSED = "images/status/paused.png";
    private static final String STATUS_COMPLETED = "images/status/completed.png";
    private static final String STATUS_ERROR = "images/status/error.png";
    private static final String STATUS_LIST = "images/status/list.png";
    private static final String TABLE_UNSORT = "images/unsort.png";
    private static final String TABLE_COLUMNS = "images/columns.png";

    public static ImageIcon getStatusStoppedIcon() {
        ImageIcon icon = imageMap.get(STATUS_STOPPED);
        if (icon == null) {
            icon = new ImageIcon(ImageLoader.class.getResource(STATUS_STOPPED));
            imageMap.put(STATUS_STOPPED, icon);
        }
        return icon;
    }
    public static ImageIcon getStatusPreparingIcon() {
        ImageIcon icon = imageMap.get(STATUS_PREPARING);
        if (icon == null) {
            icon = new ImageIcon(ImageLoader.class.getResource(STATUS_PREPARING));
            imageMap.put(STATUS_PREPARING, icon);
        }
        return icon;
    }
    public static ImageIcon getStatusWorkingIcon() {
        ImageIcon icon = imageMap.get(STATUS_WORKING);
        if (icon == null) {
            icon = new ImageIcon(ImageLoader.class.getResource(STATUS_WORKING));
            imageMap.put(STATUS_WORKING, icon);
        }
        return icon;
    }
    public static ImageIcon getStatusWaitingIcon() {
        ImageIcon icon = imageMap.get(STATUS_WAITING);
        if (icon == null) {
            icon = new ImageIcon(ImageLoader.class.getResource(STATUS_WAITING));
            imageMap.put(STATUS_WAITING, icon);
        }
        return icon;
    }
    public static ImageIcon getStatusPausedIcon() {
        ImageIcon icon = imageMap.get(STATUS_PAUSED);
        if (icon == null) {
            icon = new ImageIcon(ImageLoader.class.getResource(STATUS_PAUSED));
            imageMap.put(STATUS_PAUSED, icon);
        }
        return icon;
    }
    public static ImageIcon getStatusCompletedIcon() {
        ImageIcon icon = imageMap.get(STATUS_COMPLETED);
        if (icon == null) {
            icon = new ImageIcon(ImageLoader.class.getResource(STATUS_COMPLETED));
            imageMap.put(STATUS_COMPLETED, icon);
        }
        return icon;
    }
    public static ImageIcon getStatusErrorIcon() {
        ImageIcon icon = imageMap.get(STATUS_ERROR);
        if (icon == null) {
            icon = new ImageIcon(ImageLoader.class.getResource(STATUS_ERROR));
            imageMap.put(STATUS_ERROR, icon);
        }
        return icon;
    }
    public static ImageIcon getStatusListIcon() {
        ImageIcon icon = imageMap.get(STATUS_LIST);
        if (icon == null) {
            icon = new ImageIcon(ImageLoader.class.getResource(STATUS_LIST));
            imageMap.put(STATUS_LIST, icon);
        }
        return icon;
    }
    public static ImageIcon getUnsortIcon() {
        ImageIcon icon = imageMap.get(TABLE_UNSORT);
        if (icon == null) {
            icon = new ImageIcon(ImageLoader.class.getResource(TABLE_UNSORT));
            imageMap.put(TABLE_UNSORT, icon);
        }
        return icon;
    }
    public static ImageIcon getColumnsIcon() {
        ImageIcon icon = imageMap.get(TABLE_COLUMNS);
        if (icon == null) {
            icon = new ImageIcon(ImageLoader.class.getResource(TABLE_COLUMNS));
            imageMap.put(TABLE_COLUMNS, icon);
        }
        return icon;
    }

    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc=" status icons in 10x10 size ">

    private static final String STATUS_STOPPED_SMALL = "images/status/stopped_small.png";
    private static final String STATUS_WORKING_SMALL = "images/status/working_small.png";
    private static final String STATUS_COMPLETED_SMALL = "images/status/completed_small.png";
    private static final String STATUS_LIST_SMALL = "images/status/list_small.png";

    public static ImageIcon getStatusStoppedSmallIcon() {
        ImageIcon icon = imageMap.get(STATUS_STOPPED_SMALL);
        if (icon == null) {
            icon = new ImageIcon(ImageLoader.class.getResource(STATUS_STOPPED_SMALL));
            imageMap.put(STATUS_STOPPED_SMALL, icon);
        }
        return icon;
    }
    public static ImageIcon getStatusWorkingSmallIcon() {
        ImageIcon icon = imageMap.get(STATUS_WORKING_SMALL);
        if (icon == null) {
            icon = new ImageIcon(ImageLoader.class.getResource(STATUS_WORKING_SMALL));
            imageMap.put(STATUS_WORKING_SMALL, icon);
        }
        return icon;
    }
    public static ImageIcon getStatusCompletedSmallIcon() {
        ImageIcon icon = imageMap.get(STATUS_COMPLETED_SMALL);
        if (icon == null) {
            icon = new ImageIcon(ImageLoader.class.getResource(STATUS_COMPLETED_SMALL));
            imageMap.put(STATUS_COMPLETED_SMALL, icon);
        }
        return icon;
    }
    public static ImageIcon getStatusListSmallIcon() {
        ImageIcon icon = imageMap.get(STATUS_LIST_SMALL);
        if (icon == null) {
            icon = new ImageIcon(ImageLoader.class.getResource(STATUS_LIST_SMALL));
            imageMap.put(STATUS_LIST_SMALL, icon);
        }
        return icon;
    }

    // </editor-fold>
}
